<template>
	<view >
		<u-field
			v-model="name"
			label="昵称"
			placeholder="新昵称"
			maxlength="7"
		>
		</u-field>
		
		<view class="padding-xl">
			<button @click="submit()" :disabled="name == ''?true:false" class="cu-btn block lg bg-blue">修改</button>
		</view>
	</view>
</template>

<script>
	var _self
	export default {
		components: {
			
		},
		onLoad() {
			_self = this
		   _self.name =	_self.$store.state.user.name 
		},
		onShow() {
			
		},
		onUnload(){

			
		},
		watch:{
			
		},
		data() {
			return {
				name: ""
			}
		},
		methods: {
			submit(){
				uni.showLoading({
				    title: '修改中'
				});
				_self.xhttp.request({
					url: "/user/updateInfo", //仅为示例，并非真实接口地址。
					method:"POST",
					data: {
						name: _self.name,
						icon: _self.$store.state.user.icon
					},
					header:{
						'Content-Type':'application/json'
					}
				}).then(res => {
					if(res.data.code == 200){
						_self.toast("更换成功")
						uni.navigateBack({
							delta:1
						})
					}
					uni.hideLoading(); 
				}).catch(err => {
					uni.hideLoading(); 
				})
			}
		}
	}
</script>

<style scoped>
	
</style>